from time import *
file1 = open('m1_sorted.txt').readlines()
file2 = open('m2_reverse.txt').readlines()
file3 = open('m3_shuffle.txt').readlines()
time1_1 = time()
for i in range(len(file1) - 1):
    k = 0
    for j in range(len(file1) - i - 1):
        if file1[j] > file1[j + 1]:
            file1[j], file1[j + 1] = file1[j + 1], file1[j]
            k += 1
    if k == 0:
        break
time1_2 = time()
total1 = time1_2 - time1_1
total1 *= 1000

time2_1 = time()
for i in range(len(file2) - 1):
    k = 0
    for j in range(len(file2) - i - 1):
        if file2[j] > file2[j + 1]:
            file2[j], file2[j + 1] = file2[j + 1], file2[j]
            k += 1
    if k == 0:
        break
time2_2 = time()
total2 = int(time2_2 - time2_1)
total2 *= 1000

time3_1 = time()
for i in range(len(file3) - 1):
    k = 0
    for j in range(len(file3) - i - 1):
        if file3[j] > file3[j + 1]:
            file3[j], file3[j + 1] = file3[j + 1], file3[j]
            k += 1
    if k == 0:
        break
time3_2 = time()
total3 = int(time3_2 - time3_1)
total3 *= 1000

print('m1_sorted', int(total1), 'milliseconds')
print('m2_reverse', int(total2), 'milliseconds')
print('m3_shuffle', int(total3), 'milliseconds')
